<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title th:text="用户信息">User</title>
    <!--默认拼接前缀路径,开头请勿再添加斜杠,防止部署运行报错！-->
    <script th:replace="common/head::static"></script>
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" th:href="@{/dist/css/skins/_all-skins.min.css}">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div th:include="common/side :: side"></div>
<div class="content-wrapper">
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <!-- Horizontal Form -->
                <div class="box box-info">
                    <div class="box-header with-border">
                        <h3 class="box-title">Horizontal Form</h3>
                    </div>
                    <!-- /.box-header -->
                    <!-- form start -->
                    <form class="form-horizontal" id="editUser" style="width: 70%;" method="post">
                        <div class="box-body">
                            <div class="form-group">
                                <label for="username" class="col-sm-2 control-label">用户名</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="username" id="username" th:value="${user.username}" placeholder="Username">
                                </div>
                                <input type="hidden" name="id" th:value="${user.id}" />
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="role">角色</label>
                                <div class="col-sm-10">
                                    <select class="form-control select2" style="width: 100%;" name="role" id="role">
                                        <option value="">请选择</option>
                                        <option th:each="result : ${roleList}" th:value="${result.id}" th:text="${result.name}"></option>
                                    </select>
                                </div>
                                <input type="hidden" id="selectRole" th:value="${user.roleId}" />
                            </div>
                            <div class="form-group">
                                <label for="email" class="col-sm-2 control-label">邮箱</label>
                                <div class="col-sm-10">
                                    <input type="email" class="form-control" name="email" id="email" th:value="${user.email}" placeholder="Email">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="telphone" class="col-sm-2 control-label">电话</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="telphone" id="telphone" th:value="${user.telphone}" placeholder="telphone">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="realName" class="col-sm-2 control-label">真实姓名</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="realName" id="realName" th:value="${user.realName}" placeholder="realName">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="age" class="col-sm-2 control-label">年龄</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="age" id="age" th:value="${user.age}" placeholder="age">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-10">
<!--                                    <input type="submit" value="提交" class="btn btn-info" />-->
                                    <a href="javascript:toedit()" class="btn btn-info">提交</a>
<!--                                    <input type="reset" value="重置" class="btn btn-info" />-->
                                    <a href="javascript:history.go(-1)" class="btn btn-default">返回</a>
                                </div>

                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
</div>
<!-- ./wrapper -->
<div th:replace="~{common/footer :: footer}">...</div>
<!-- JavaScript -->
</body>
<script>
    $(function () {
        var selectRole = $("#selectRole").val()
        $( "#role" ).val( selectRole );
    });
    function toedit() {
        var obj=$("#editUser").serialize();
        console.log(obj)
        $.ajax({
            url : "/user/toEdit",
            type : "post",
            contentType:"application/x-www-form-urlencoded",
            data :obj,
            dataType : "json",
            success : function(data) {
                if(data.status == "success") {
                    layer.msg('用户修改成功', {time: 3000, icon:6},function () {
                        location.href = "/user/list"
                    });
                } else {
                    layer.msg("用户修改失败，原因为"+ data.data.errMsg, {time: 3000, icon:6});
                }
            }
        });
    }
</script>
</html>
